/***************************************************************
 * Name:      mcs_51_rom.c
 * Purpose:   实现mcs_51_rom接口
 * Author:    HYH (hyhsystem.cn)
 * Created:   2025-02-13
 * Copyright: HYH (hyhsystem.cn)
 * License:   MIT
 **************************************************************/
#include "mcs_51_rom.h"

bool hs_mcs_51_rom_read(hs_mcs_51_rom_t rom,uint32_t addr,uint8_t *data)
{
    if(rom.code==NULL || data==NULL)
    {
        return false;
    }

    if(addr < rom.len)
    {
        (*data)=(uint8_t)rom.code[addr];
        return true;
    }

    return false;
}

void hs_mcs_51_rom_bus_io(hs_mcs_51_core_t *core,hs_mcs_51_io_opt_t opt,uint16_t address,uint8_t *data,uint16_t length,void *usr,hs_mcs_51_rom_t *rom)
{
    if(opt==HS_MCS_51_IO_RESET)
    {
        if(rom!=NULL)
        {
            if((rom->code!=NULL)&& (rom->len > (64*1024)))
            {
                //超过2个Bank
                uint8_t psbank_addr=HS_MCS_51_ROM_PSBANK_C8051F120_SFR_ADDRESS;
                if(rom->psbank_addr >= 0x80)
                {
                    psbank_addr=rom->psbank_addr;
                }
                uint8_t psbank_val=0x11;
                if(psbank_addr==HS_MCS_51_ROM_PSBANK_CC2530_SFR_ADDRESS)
                {
                    //对于CC2530而言，PSBANK为FMAP寄存器，不区分常数与指令，因此常数访问同指令访问
                    psbank_val=0x01;
                }
                //常数Bank与指令Bank选择1
                hs_mcs_51_sfr_write(core,(hs_mcs_51_sfr_addr_t)psbank_addr, psbank_val);
            }
        }
    }

    if(opt==HS_MCS_51_IO_READ_ROM)
    {
        if(rom!=NULL)
        {
            //使用size_t用作临时地址
            size_t address_size_t=address;

            if((rom->code!=NULL))
            {
                //使用size_t用作地址,16位地址在地址映射后可能溢出
                size_t address=address_size_t;

                //进行地址映射
                if((rom->code!=NULL)&& (rom->len > (64*1024)))
                {
                    //超过2个Bank(未超过64KB不启用PSBANK)
                    uint8_t psbank_addr=HS_MCS_51_ROM_PSBANK_C8051F120_SFR_ADDRESS;
                    if(rom->psbank_addr >= 0x80)
                    {
                        psbank_addr=rom->psbank_addr;
                    }
                    uint8_t psbank_val=0x11;
                    hs_mcs_51_sfr_read(core,(hs_mcs_51_sfr_addr_t)psbank_addr,&psbank_val);
                    if(address >= 0x8000)
                    {
                        //访问高地址，需要进行Bank选择,低地址永远访问Bank0

                        address-=0x8000;
                        if(psbank_addr==HS_MCS_51_ROM_PSBANK_CC2530_SFR_ADDRESS)
                        {
                            //对于CC2530而言，PSBANK为FMAP寄存器，不区分常数与指令，因此常数访问同指令访问
                            psbank_val&=0x0F;
                            psbank_val+=(psbank_val<<4);
                        }
                        if(length == 1)
                        {
                            //常数访问
                            address+=(((psbank_val&0xF0)>>4)*0x8000);
                        }
                        else
                        {
                            //指令访问
                            address+=((psbank_val&0xF)*0x8000);
                        }
                    }
                }


                //读取数据
                if((rom->len >= (address+length)) )
                {
                    memcpy(data,&rom->code[address],length);
                    //成功读取指令
                    return;
                }
                else if((rom->len > (address)))
                {
                    memcpy(data,&rom->code[address],rom->len-address);
                    //成功读取指令
                    return;
                }
            }
        }
        {
            //失败跳转至0地址
            uint8_t ljmp_zero[]= {0x02,0x00,0x00};
            memcpy(data,ljmp_zero,(length>sizeof(ljmp_zero))?(sizeof(ljmp_zero)):(length));
        }
    }
}

/*
*  helloworld程序(见rom/helloworld目录)
*/
static const unsigned char hs_mcs_51_rom_helloworld_bin[] = {
    0x02, 0x00, 0x29, 0x02, 0x00, 0x85, 0xff, 0xff, 0xff, 0xff, 0xff, 0x02,
    0x00, 0x86, 0xff, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0x87, 0xff, 0xff,
    0xff, 0xff, 0xff, 0x02, 0x00, 0x88, 0xff, 0xff, 0xff, 0xff, 0xff, 0x02,
    0x00, 0x89, 0x02, 0x00, 0xd0, 0x75, 0x81, 0x09, 0x12, 0x02, 0xe3, 0xe5,
    0x82, 0x60, 0x03, 0x02, 0x00, 0x26, 0x79, 0x00, 0xe9, 0x44, 0x00, 0x60,
    0x1b, 0x7a, 0x00, 0x90, 0x03, 0x10, 0x78, 0x01, 0x75, 0xa0, 0x00, 0xe4,
    0x93, 0xf2, 0xa3, 0x08, 0xb8, 0x00, 0x02, 0x05, 0xa0, 0xd9, 0xf4, 0xda,
    0xf2, 0x75, 0xa0, 0xff, 0xe4, 0x78, 0x7f, 0xf6, 0xd8, 0xfd, 0x78, 0x00,
    0xe8, 0x44, 0x00, 0x60, 0x0a, 0x79, 0x01, 0x75, 0xa0, 0x00, 0xe4, 0xf3,
    0x09, 0xd8, 0xfc, 0x78, 0x00, 0xe8, 0x44, 0x00, 0x60, 0x0c, 0x79, 0x00,
    0x90, 0x00, 0x01, 0xe4, 0xf0, 0xa3, 0xd8, 0xfc, 0xd9, 0xfa, 0x02, 0x00,
    0x26, 0x32, 0x32, 0x32, 0x32, 0x32, 0x75, 0x98, 0x90, 0x22, 0xae, 0x82,
    0x8e, 0x99, 0x10, 0x99, 0x02, 0x80, 0xfb, 0x22, 0x30, 0x98, 0xfd, 0x85,
    0x99, 0x82, 0xc2, 0x98, 0x22, 0xad, 0x82, 0xae, 0x83, 0xaf, 0xf0, 0x8d,
    0x82, 0x8e, 0x83, 0x8f, 0xf0, 0x12, 0x02, 0x59, 0xfc, 0x60, 0x1c, 0x0d,
    0xbd, 0x00, 0x01, 0x0e, 0x7b, 0x00, 0x8c, 0x82, 0x8b, 0x83, 0xc0, 0x07,
    0xc0, 0x06, 0xc0, 0x05, 0x12, 0x00, 0x8e, 0xd0, 0x05, 0xd0, 0x06, 0xd0,
    0x07, 0x80, 0xd8, 0x22, 0x12, 0x00, 0x8a, 0x90, 0x02, 0xe7, 0x75, 0xf0,
    0x80, 0x12, 0x00, 0xa1, 0x90, 0x02, 0xf5, 0x75, 0xf0, 0x80, 0x12, 0x00,
    0xa1, 0x7f, 0x01, 0xef, 0x24, 0xf6, 0x50, 0x03, 0x02, 0x01, 0xd7, 0x7e,
    0x01, 0xc3, 0xef, 0x9e, 0x50, 0x03, 0x02, 0x01, 0xc9, 0x8f, 0x04, 0x7d,
    0x00, 0x74, 0x30, 0x2c, 0xf5, 0x82, 0xe4, 0x3d, 0xf5, 0x83, 0xc0, 0x07,
    0xc0, 0x06, 0x12, 0x00, 0x8e, 0x90, 0x00, 0x2a, 0x12, 0x00, 0x8e, 0xd0,
    0x06, 0x8e, 0x04, 0x7d, 0x00, 0x74, 0x30, 0x2c, 0xf5, 0x82, 0xe4, 0x3d,
    0xf5, 0x83, 0xc0, 0x06, 0x12, 0x00, 0x8e, 0x90, 0x00, 0x3d, 0x12, 0x00,
    0x8e, 0xd0, 0x06, 0xd0, 0x07, 0x8f, 0xf0, 0xee, 0xa4, 0xfc, 0xad, 0xf0,
    0xc3, 0xec, 0x94, 0x0a, 0xed, 0x64, 0x80, 0x94, 0x80, 0x40, 0x26, 0x75,
    0x08, 0x0a, 0x75, 0x09, 0x00, 0x8c, 0x82, 0x8d, 0x83, 0xc0, 0x07, 0xc0,
    0x06, 0x12, 0x02, 0xab, 0xe5, 0x82, 0x85, 0x83, 0xf0, 0x24, 0x30, 0xf5,
    0x82, 0xe4, 0x35, 0xf0, 0xf5, 0x83, 0x12, 0x00, 0x8e, 0xd0, 0x06, 0xd0,
    0x07, 0x8f, 0xf0, 0xee, 0xa4, 0xfc, 0xad, 0xf0, 0x75, 0x08, 0x0a, 0x75,
    0x09, 0x00, 0x8c, 0x82, 0x8d, 0x83, 0xc0, 0x07, 0xc0, 0x06, 0xc0, 0x05,
    0xc0, 0x04, 0x12, 0x02, 0x75, 0xe5, 0x82, 0x85, 0x83, 0xf0, 0x24, 0x30,
    0xf5, 0x82, 0xe4, 0x35, 0xf0, 0xf5, 0x83, 0x12, 0x00, 0x8e, 0xd0, 0x04,
    0xd0, 0x05, 0xd0, 0x06, 0xd0, 0x07, 0xc3, 0xec, 0x94, 0x0a, 0xed, 0x64,
    0x80, 0x94, 0x80, 0x50, 0x0e, 0x90, 0x00, 0x20, 0xc0, 0x07, 0xc0, 0x06,
    0x12, 0x00, 0x8e, 0xd0, 0x06, 0xd0, 0x07, 0x90, 0x00, 0x20, 0xc0, 0x07,
    0xc0, 0x06, 0x12, 0x00, 0x8e, 0xd0, 0x06, 0xd0, 0x07, 0x0e, 0x02, 0x00,
    0xf1, 0x90, 0x00, 0x0a, 0xc0, 0x07, 0x12, 0x00, 0x8e, 0xd0, 0x07, 0x0f,
    0x02, 0x00, 0xe7, 0x12, 0x00, 0x98, 0x7e, 0x00, 0x8e, 0x83, 0x12, 0x00,
    0x8e, 0x80, 0xf4, 0xe5, 0x08, 0x45, 0x09, 0x60, 0x46, 0x7a, 0x01, 0xe5,
    0x08, 0x25, 0xe0, 0xf5, 0x08, 0xe5, 0x09, 0x33, 0x40, 0x12, 0xf5, 0x09,
    0xe5, 0x82, 0x95, 0x08, 0xe5, 0x83, 0x95, 0x09, 0x40, 0x03, 0x0a, 0x80,
    0xe6, 0xc3, 0xe5, 0x09, 0x13, 0xf5, 0x09, 0xe5, 0x08, 0x13, 0xf5, 0x08,
    0xc3, 0xe5, 0x82, 0x95, 0x08, 0xf5, 0xf0, 0xe5, 0x83, 0x95, 0x09, 0x40,
    0x05, 0xf5, 0x83, 0x85, 0xf0, 0x82, 0xc3, 0xe5, 0x09, 0x13, 0xf5, 0x09,
    0xe5, 0x08, 0x13, 0xf5, 0x08, 0xda, 0xe1, 0x22, 0x7a, 0x10, 0xe4, 0xfb,
    0xfc, 0xe5, 0x82, 0x25, 0xe0, 0xf5, 0x82, 0xe5, 0x83, 0x33, 0xf5, 0x83,
    0xeb, 0x33, 0xfb, 0xec, 0x33, 0xfc, 0xeb, 0x95, 0x08, 0xf5, 0xf0, 0xec,
    0x95, 0x09, 0x40, 0x06, 0xfc, 0xab, 0xf0, 0x43, 0x82, 0x01, 0xda, 0xdd,
    0x22, 0x20, 0xf7, 0x14, 0x30, 0xf6, 0x14, 0x88, 0x83, 0xa8, 0x82, 0x20,
    0xf5, 0x07, 0xe6, 0xa8, 0x83, 0x75, 0x83, 0x00, 0x22, 0xe2, 0x80, 0xf7,
    0xe4, 0x93, 0x22, 0xe0, 0x22, 0xc2, 0xd5, 0xe5, 0x83, 0x30, 0xe7, 0x0d,
    0xd2, 0xd5, 0xe4, 0xc3, 0x95, 0x82, 0xf5, 0x82, 0xe4, 0x95, 0x83, 0xf5,
    0x83, 0xe5, 0x09, 0x30, 0xe7, 0x0b, 0xe4, 0xc3, 0x95, 0x08, 0xf5, 0x08,
    0xe4, 0x95, 0x09, 0xf5, 0x09, 0x12, 0x01, 0xe3, 0x30, 0xd5, 0x0b, 0xe4,
    0xc3, 0x95, 0x82, 0xf5, 0x82, 0xe4, 0x95, 0x83, 0xf5, 0x83, 0x22, 0xc2,
    0xd5, 0xe5, 0x83, 0x30, 0xe7, 0x0d, 0xd2, 0xd5, 0xe4, 0xc3, 0x95, 0x82,
    0xf5, 0x82, 0xe4, 0x95, 0x83, 0xf5, 0x83, 0xe5, 0x09, 0x30, 0xe7, 0x0d,
    0xb2, 0xd5, 0xe4, 0xc3, 0x95, 0x08, 0xf5, 0x08, 0xe4, 0x95, 0x09, 0xf5,
    0x09, 0x12, 0x02, 0x30, 0x30, 0xd5, 0x0b, 0xe4, 0xc3, 0x95, 0x82, 0xf5,
    0x82, 0xe4, 0x95, 0x83, 0xf5, 0x83, 0x22, 0x75, 0x82, 0x00, 0x22, 0x48,
    0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21, 0x0a,
    0x00, 0x39, 0x78, 0x39, 0x20, 0x6d, 0x75, 0x6c, 0x74, 0x69, 0x70, 0x6c,
    0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74, 0x61, 0x62, 0x6c,
    0x65, 0x3a, 0x0a, 0x00
};
#define hs_mcs_51_rom_helloworld_len  784

const hs_mcs_51_rom_t hs_mcs_51_rom_helloworld=
{
    hs_mcs_51_rom_helloworld_bin,
    hs_mcs_51_rom_helloworld_len,
    HS_MCS_51_ROM_PSBANK_C8051F120_SFR_ADDRESS
};

/*
*  helloworld_stdio程序(见rom/helloworld_stdio目录)
*/
static const unsigned char hs_mcs_51_rom_helloworld_stdio_bin[] = {
    0x02, 0x00, 0x29, 0x02, 0x00, 0x85, 0xff, 0xff, 0xff, 0xff, 0xff, 0x02,
    0x00, 0x86, 0xff, 0xff, 0xff, 0xff, 0xff, 0x02, 0x00, 0x87, 0xff, 0xff,
    0xff, 0xff, 0xff, 0x02, 0x00, 0x88, 0xff, 0xff, 0xff, 0xff, 0xff, 0x02,
    0x00, 0x89, 0x02, 0x00, 0xe4, 0x75, 0x81, 0x40, 0x12, 0x09, 0x0a, 0xe5,
    0x82, 0x60, 0x03, 0x02, 0x00, 0x26, 0x79, 0x00, 0xe9, 0x44, 0x00, 0x60,
    0x1b, 0x7a, 0x00, 0x90, 0x09, 0x50, 0x78, 0x01, 0x75, 0xa0, 0x00, 0xe4,
    0x93, 0xf2, 0xa3, 0x08, 0xb8, 0x00, 0x02, 0x05, 0xa0, 0xd9, 0xf4, 0xda,
    0xf2, 0x75, 0xa0, 0xff, 0xe4, 0x78, 0x7f, 0xf6, 0xd8, 0xfd, 0x78, 0x00,
    0xe8, 0x44, 0x00, 0x60, 0x0a, 0x79, 0x01, 0x75, 0xa0, 0x00, 0xe4, 0xf3,
    0x09, 0xd8, 0xfc, 0x78, 0x00, 0xe8, 0x44, 0x00, 0x60, 0x0c, 0x79, 0x00,
    0x90, 0x00, 0x01, 0xe4, 0xf0, 0xa3, 0xd8, 0xfc, 0xd9, 0xfa, 0x02, 0x00,
    0x26, 0x32, 0x32, 0x32, 0x32, 0x32, 0x75, 0x98, 0x90, 0x22, 0xae, 0x82,
    0x8e, 0x99, 0x10, 0x99, 0x02, 0x80, 0xfb, 0x22, 0x30, 0x98, 0xfd, 0x85,
    0x99, 0x82, 0xc2, 0x98, 0x22, 0xad, 0x82, 0xae, 0x83, 0xaf, 0xf0, 0x8d,
    0x82, 0x8e, 0x83, 0x8f, 0xf0, 0x12, 0x08, 0xee, 0xfc, 0x60, 0x1c, 0x0d,
    0xbd, 0x00, 0x01, 0x0e, 0x7b, 0x00, 0x8c, 0x82, 0x8b, 0x83, 0xc0, 0x07,
    0xc0, 0x06, 0xc0, 0x05, 0x12, 0x00, 0x8e, 0xd0, 0x05, 0xd0, 0x06, 0xd0,
    0x07, 0x80, 0xd8, 0x22, 0xae, 0x82, 0xaf, 0x83, 0xc0, 0x07, 0xc0, 0x06,
    0x12, 0x00, 0x8e, 0xd0, 0x06, 0xd0, 0x07, 0x8e, 0x82, 0x8f, 0x83, 0x22,
    0x12, 0x00, 0x8a, 0x74, 0x0e, 0xc0, 0xe0, 0x74, 0x09, 0xc0, 0xe0, 0x74,
    0x80, 0xc0, 0xe0, 0x12, 0x01, 0xaa, 0x15, 0x81, 0x15, 0x81, 0x15, 0x81,
    0x74, 0x1c, 0xc0, 0xe0, 0x74, 0x09, 0xc0, 0xe0, 0x74, 0x80, 0xc0, 0xe0,
    0x12, 0x01, 0xaa, 0x15, 0x81, 0x15, 0x81, 0x15, 0x81, 0x7f, 0x01, 0xef,
    0x24, 0xf6, 0x40, 0x5e, 0x7e, 0x01, 0xc3, 0xef, 0x9e, 0x40, 0x3b, 0x8f,
    0xf0, 0xee, 0xa4, 0xfc, 0xad, 0xf0, 0x8e, 0x02, 0x7b, 0x00, 0x8f, 0x00,
    0x79, 0x00, 0xc0, 0x07, 0xc0, 0x06, 0xc0, 0x04, 0xc0, 0x05, 0xc0, 0x02,
    0xc0, 0x03, 0xc0, 0x00, 0xc0, 0x01, 0x74, 0x37, 0xc0, 0xe0, 0x74, 0x09,
    0xc0, 0xe0, 0x74, 0x80, 0xc0, 0xe0, 0x12, 0x01, 0xaa, 0xe5, 0x81, 0x24,
    0xf7, 0xf5, 0x81, 0xd0, 0x06, 0xd0, 0x07, 0x0e, 0x80, 0xc0, 0xc0, 0x07,
    0x74, 0x43, 0xc0, 0xe0, 0x74, 0x09, 0xc0, 0xe0, 0x74, 0x80, 0xc0, 0xe0,
    0x12, 0x01, 0xaa, 0x15, 0x81, 0x15, 0x81, 0x15, 0x81, 0xd0, 0x07, 0x0f,
    0x80, 0x9d, 0x12, 0x00, 0x98, 0x7e, 0x00, 0x8e, 0x83, 0x12, 0x00, 0x8e,
    0x80, 0xf4, 0xc0, 0x37, 0x85, 0x81, 0x37, 0x7e, 0x00, 0x8e, 0x83, 0x12,
    0x00, 0xd0, 0xd0, 0x37, 0x22, 0x85, 0x82, 0x19, 0x85, 0x83, 0x1a, 0x85,
    0xf0, 0x1b, 0xe4, 0xf5, 0x16, 0xf5, 0x17, 0xf5, 0x18, 0x85, 0x08, 0x1c,
    0x90, 0x01, 0x82, 0x02, 0x02, 0x6b, 0xc0, 0x37, 0xe5, 0x81, 0xf5, 0x37,
    0x24, 0xfb, 0xff, 0x8f, 0x1c, 0xe4, 0xf5, 0x16, 0xf5, 0x17, 0xf5, 0x18,
    0xe5, 0x37, 0x24, 0xfb, 0xf8, 0x86, 0x19, 0x08, 0x86, 0x1a, 0x08, 0x86,
    0x1b, 0x90, 0x01, 0x82, 0x12, 0x02, 0x6b, 0xd0, 0x37, 0x22, 0xaf, 0x82,
    0xc0, 0x0c, 0xc0, 0x0d, 0xc0, 0x0e, 0x12, 0x01, 0xdf, 0x80, 0x07, 0xc0,
    0x0a, 0xc0, 0x0b, 0x8f, 0x82, 0x22, 0x15, 0x81, 0x15, 0x81, 0x15, 0x81,
    0x05, 0x14, 0xe4, 0xb5, 0x14, 0x02, 0x05, 0x15, 0x22, 0xaf, 0x82, 0x74,
    0x30, 0x2f, 0xff, 0x24, 0xc6, 0x50, 0x0b, 0x74, 0x07, 0x2f, 0xff, 0xe5,
    0x09, 0x60, 0x03, 0x43, 0x07, 0x20, 0x8f, 0x82, 0x02, 0x01, 0xd2, 0xe5,
    0x82, 0xff, 0xc4, 0x54, 0x0f, 0xf5, 0x82, 0xc0, 0x07, 0x12, 0x01, 0xf5,
    0xd0, 0x07, 0x74, 0x0f, 0x5f, 0xf5, 0x82, 0x02, 0x01, 0xf5, 0x85, 0x82,
    0x38, 0xab, 0x0f, 0xac, 0x10, 0xad, 0x11, 0xae, 0x12, 0xaa, 0x13, 0x75,
    0x3a, 0x20, 0x8a, 0x07, 0xef, 0x2f, 0xf5, 0x39, 0xee, 0x23, 0x54, 0x01,
    0x45, 0x39, 0xfa, 0xeb, 0x2b, 0xfb, 0xec, 0x33, 0xfc, 0xed, 0x33, 0xfd,
    0xee, 0x33, 0xfe, 0xc3, 0xea, 0x95, 0x38, 0x40, 0x08, 0xea, 0xc3, 0x95,
    0x38, 0xfa, 0x43, 0x03, 0x01, 0xd5, 0x3a, 0xd6, 0x8b, 0x0f, 0x8c, 0x10,
    0x8d, 0x11, 0x8e, 0x12, 0x8a, 0x13, 0x22, 0x85, 0x82, 0x0a, 0x85, 0x83,
    0x0b, 0x85, 0x16, 0x0c, 0x85, 0x17, 0x0d, 0x85, 0x18, 0x0e, 0xe4, 0xf5,
    0x14, 0xf5, 0x15, 0xad, 0x19, 0xae, 0x1a, 0xaf, 0x1b, 0x8d, 0x82, 0x8e,
    0x83, 0x8f, 0xf0, 0x12, 0x08, 0xee, 0xfc, 0x74, 0x01, 0x2d, 0xf5, 0x19,
    0xe4, 0x3e, 0xf5, 0x1a, 0x8f, 0x1b, 0xec, 0xff, 0x70, 0x03, 0x02, 0x08,
    0xb2, 0xbf, 0x25, 0x02, 0x80, 0x03, 0x02, 0x08, 0xaa, 0xe4, 0xf5, 0x1d,
    0xf5, 0x1e, 0xf5, 0x1f, 0xf5, 0x20, 0xf5, 0x21, 0xf5, 0x22, 0xf5, 0x23,
    0xf5, 0x24, 0xf5, 0x26, 0xf5, 0x33, 0xf5, 0x34, 0x75, 0x27, 0xff, 0x75,
    0x28, 0xff, 0x85, 0x19, 0x2d, 0x85, 0x1a, 0x2e, 0x85, 0x1b, 0x2f, 0x85,
    0x2d, 0x82, 0x85, 0x2e, 0x83, 0x85, 0x2f, 0xf0, 0x12, 0x08, 0xee, 0xf5,
    0x30, 0xa3, 0x85, 0x82, 0x2d, 0x85, 0x83, 0x2e, 0x85, 0x2d, 0x19, 0x85,
    0x2e, 0x1a, 0x85, 0x2f, 0x1b, 0x74, 0x25, 0xb5, 0x30, 0x08, 0x85, 0x30,
    0x82, 0x12, 0x01, 0xd2, 0x80, 0x85, 0x74, 0xd0, 0x25, 0x30, 0x50, 0x68,
    0xe5, 0x30, 0x24, 0xc6, 0x40, 0x62, 0x74, 0xff, 0xb5, 0x27, 0x36, 0xb5,
    0x28, 0x33, 0x85, 0x33, 0x38, 0x85, 0x34, 0x39, 0x90, 0x00, 0x0a, 0x12,
    0x08, 0xd1, 0x85, 0x82, 0x31, 0x85, 0x83, 0x32, 0xaa, 0x30, 0x7e, 0x00,
    0xea, 0x25, 0x31, 0xfa, 0xee, 0x35, 0x32, 0xfe, 0xea, 0x24, 0xd0, 0xf5,
    0x33, 0xee, 0x34, 0xff, 0xf5, 0x34, 0xe5, 0x33, 0x45, 0x34, 0x70, 0x93,
    0x75, 0x1e, 0x01, 0x80, 0x8e, 0x85, 0x27, 0x38, 0x85, 0x28, 0x39, 0x90,
    0x00, 0x0a, 0x12, 0x08, 0xd1, 0xae, 0x82, 0xab, 0x83, 0xaa, 0x30, 0x7d,
    0x00, 0xea, 0x2e, 0xfe, 0xed, 0x3b, 0xfb, 0xee, 0x24, 0xd0, 0xf5, 0x27,
    0xeb, 0x34, 0xff, 0xf5, 0x28, 0x02, 0x02, 0xcf, 0x74, 0x2e, 0xb5, 0x30,
    0x15, 0x74, 0xff, 0xb5, 0x27, 0x05, 0xb5, 0x28, 0x02, 0x80, 0x03, 0x02,
    0x02, 0xcf, 0xe4, 0xf5, 0x27, 0xf5, 0x28, 0x02, 0x02, 0xcf, 0x74, 0x9f,
    0x25, 0x30, 0x50, 0x0e, 0xe5, 0x30, 0x24, 0x85, 0x40, 0x08, 0x53, 0x30,
    0xdf, 0x75, 0x09, 0x01, 0x80, 0x03, 0x75, 0x09, 0x00, 0x74, 0x20, 0xb5,
    0x30, 0x03, 0x02, 0x04, 0x35, 0x74, 0x2b, 0xb5, 0x30, 0x03, 0x02, 0x04,
    0x2f, 0x74, 0x2d, 0xb5, 0x30, 0x02, 0x80, 0x79, 0x74, 0x42, 0xb5, 0x30,
    0x03, 0x02, 0x04, 0x3b, 0x74, 0x43, 0xb5, 0x30, 0x03, 0x02, 0x04, 0x47,
    0x74, 0x44, 0xb5, 0x30, 0x03, 0x02, 0x05, 0xcb, 0x74, 0x46, 0xb5, 0x30,
    0x03, 0x02, 0x05, 0xe2, 0x74, 0x48, 0xb5, 0x30, 0x03, 0x02, 0x02, 0xcf,
    0x74, 0x49, 0xb5, 0x30, 0x03, 0x02, 0x05, 0xcb, 0x74, 0x4a, 0xb5, 0x30,
    0x03, 0x02, 0x02, 0xcf, 0x74, 0x4c, 0xb5, 0x30, 0x02, 0x80, 0x52, 0x74,
    0x4f, 0xb5, 0x30, 0x03, 0x02, 0x05, 0xd3, 0x74, 0x50, 0xb5, 0x30, 0x03,
    0x02, 0x05, 0x60, 0x74, 0x53, 0xb5, 0x30, 0x02, 0x80, 0x62, 0x74, 0x54,
    0xb5, 0x30, 0x03, 0x02, 0x02, 0xcf, 0x74, 0x55, 0xb5, 0x30, 0x03, 0x02,
    0x05, 0xd8, 0x74, 0x58, 0xb5, 0x30, 0x03, 0x02, 0x05, 0xdd, 0x74, 0x5a,
    0xb5, 0x30, 0x03, 0x02, 0x02, 0xcf, 0x02, 0x05, 0xe7, 0x75, 0x1d, 0x01,
    0x02, 0x02, 0xcf, 0x75, 0x1f, 0x01, 0x02, 0x02, 0xcf, 0x75, 0x20, 0x01,
    0x02, 0x02, 0xcf, 0x75, 0x22, 0x01, 0x02, 0x02, 0xcf, 0x75, 0x23, 0x01,
    0x02, 0x02, 0xcf, 0xe5, 0x22, 0x60, 0x0a, 0xe5, 0x1c, 0x14, 0xf9, 0x89,
    0x1c, 0x87, 0x06, 0x80, 0x0b, 0xe5, 0x1c, 0x24, 0xfe, 0xfb, 0x8b, 0x1c,
    0x8b, 0x01, 0x87, 0x06, 0x8e, 0x82, 0x12, 0x01, 0xd2, 0x02, 0x05, 0xf5,
    0xe5, 0x1c, 0x24, 0xfd, 0xfe, 0x8e, 0x1c, 0x8e, 0x01, 0x87, 0x02, 0x09,
    0x87, 0x03, 0x09, 0x87, 0x06, 0x19, 0x19, 0x8a, 0x0f, 0x8b, 0x10, 0x8e,
    0x11, 0x8a, 0x82, 0x8b, 0x83, 0x8e, 0xf0, 0x12, 0x08, 0xb9, 0x85, 0x82,
    0x2d, 0x85, 0x83, 0x2e, 0x74, 0xff, 0xb5, 0x27, 0x09, 0xb5, 0x28, 0x06,
    0x85, 0x2d, 0x27, 0x85, 0x2e, 0x28, 0xe5, 0x1d, 0x70, 0x37, 0xc3, 0xe5,
    0x2d, 0x95, 0x33, 0xe5, 0x2e, 0x95, 0x34, 0x50, 0x2c, 0xe5, 0x33, 0xc3,
    0x95, 0x2d, 0xf5, 0x31, 0xe5, 0x34, 0x95, 0x2e, 0xf5, 0x32, 0xaa, 0x31,
    0xae, 0x32, 0x15, 0x31, 0x74, 0xff, 0xb5, 0x31, 0x02, 0x15, 0x32, 0xea,
    0x4e, 0x60, 0x08, 0x75, 0x82, 0x20, 0x12, 0x01, 0xd2, 0x80, 0xe7, 0x85,
    0x31, 0x33, 0x85, 0x32, 0x34, 0xab, 0x27, 0xae, 0x28, 0x85, 0x0f, 0x82,
    0x85, 0x10, 0x83, 0x85, 0x11, 0xf0, 0x12, 0x08, 0xee, 0xfa, 0x8a, 0x2b,
    0x60, 0x34, 0xc3, 0xe4, 0x9b, 0x74, 0x80, 0x8e, 0xf0, 0x63, 0xf0, 0x80,
    0x95, 0xf0, 0x50, 0x26, 0x1b, 0xbb, 0xff, 0x01, 0x1e, 0x85, 0x2b, 0x82,
    0xc0, 0x06, 0xc0, 0x03, 0x12, 0x01, 0xd2, 0xd0, 0x03, 0xd0, 0x06, 0xaa,
    0x0f, 0xac, 0x10, 0xad, 0x11, 0x0a, 0xba, 0x00, 0x01, 0x0c, 0x8a, 0x0f,
    0x8c, 0x10, 0x8d, 0x11, 0x80, 0xbb, 0xe5, 0x1d, 0x70, 0x03, 0x02, 0x05,
    0xf5, 0xc3, 0xe5, 0x2d, 0x95, 0x33, 0xe5, 0x2e, 0x95, 0x34, 0x40, 0x03,
    0x02, 0x05, 0xf5, 0xe5, 0x33, 0xc3, 0x95, 0x2d, 0xf5, 0x31, 0xe5, 0x34,
    0x95, 0x2e, 0xf5, 0x32, 0xaa, 0x31, 0xae, 0x32, 0x15, 0x31, 0x74, 0xff,
    0xb5, 0x31, 0x02, 0x15, 0x32, 0xea, 0x4e, 0x70, 0x03, 0x02, 0x05, 0xef,
    0x75, 0x82, 0x20, 0x12, 0x01, 0xd2, 0x80, 0xe4, 0xe5, 0x1c, 0x24, 0xfd,
    0xfe, 0x8e, 0x1c, 0x8e, 0x01, 0x87, 0x02, 0x09, 0x87, 0x03, 0x09, 0x87,
    0x06, 0x19, 0x19, 0x8a, 0x0f, 0x8b, 0x10, 0x8e, 0x11, 0xae, 0x11, 0xbe,
    0x80, 0x00, 0x40, 0x04, 0x7b, 0x43, 0x80, 0x14, 0xbe, 0x60, 0x00, 0x40,
    0x04, 0x7b, 0x50, 0x80, 0x0b, 0xbe, 0x40, 0x00, 0x40, 0x04, 0x7b, 0x49,
    0x80, 0x02, 0x7b, 0x58, 0x8b, 0x82, 0xc0, 0x03, 0x12, 0x01, 0xd2, 0x75,
    0x82, 0x3a, 0x12, 0x01, 0xd2, 0x75, 0x82, 0x30, 0x12, 0x01, 0xd2, 0x75,
    0x82, 0x78, 0x12, 0x01, 0xd2, 0xd0, 0x03, 0xbb, 0x49, 0x02, 0x80, 0x0b,
    0xbb, 0x50, 0x02, 0x80, 0x06, 0x85, 0x10, 0x82, 0x12, 0x02, 0x0f, 0x85,
    0x0f, 0x82, 0x12, 0x02, 0x0f, 0x80, 0x2a, 0x75, 0x21, 0x01, 0x75, 0x26,
    0x0a, 0x80, 0x22, 0x75, 0x26, 0x08, 0x80, 0x1d, 0x75, 0x26, 0x0a, 0x80,
    0x18, 0x75, 0x26, 0x10, 0x80, 0x13, 0x75, 0x24, 0x01, 0x80, 0x0e, 0x85,
    0x30, 0x82, 0x12, 0x01, 0xd2, 0x80, 0x06, 0x85, 0x31, 0x33, 0x85, 0x32,
    0x34, 0xe5, 0x24, 0x60, 0x60, 0xe5, 0x1c, 0x24, 0xfc, 0xfe, 0x8e, 0x1c,
    0x8e, 0x01, 0x87, 0x33, 0x09, 0x87, 0x34, 0x09, 0x87, 0x35, 0x09, 0x87,
    0x36, 0x19, 0x19, 0x19, 0x85, 0x33, 0x0f, 0x85, 0x34, 0x10, 0x85, 0x35,
    0x11, 0x85, 0x36, 0x12, 0x75, 0x0f, 0x45, 0x75, 0x10, 0x09, 0x75, 0x11,
    0x80, 0x85, 0x0f, 0x33, 0x85, 0x10, 0x34, 0x85, 0x11, 0x35, 0x74, 0x01,
    0x25, 0x33, 0xfa, 0xe4, 0x35, 0x34, 0xfb, 0xae, 0x35, 0x8a, 0x0f, 0x8b,
    0x10, 0x8e, 0x11, 0x85, 0x33, 0x82, 0x85, 0x34, 0x83, 0x85, 0x35, 0xf0,
    0x12, 0x08, 0xee, 0xfe, 0xfb, 0x70, 0x03, 0x02, 0x02, 0x7f, 0x8b, 0x82,
    0x12, 0x01, 0xd2, 0x80, 0xcc, 0xe5, 0x26, 0x70, 0x03, 0x02, 0x02, 0x7f,
    0xe5, 0x22, 0x60, 0x2b, 0xe5, 0x1c, 0x14, 0xf9, 0x89, 0x1c, 0x87, 0x06,
    0x8e, 0x02, 0x7b, 0x00, 0x7d, 0x00, 0x7e, 0x00, 0x8a, 0x0f, 0x8b, 0x10,
    0x8d, 0x11, 0x8e, 0x12, 0xe5, 0x21, 0x70, 0x64, 0xaa, 0x0f, 0xfb, 0xfd,
    0xfe, 0x8a, 0x0f, 0x8b, 0x10, 0x8d, 0x11, 0x8e, 0x12, 0x80, 0x55, 0xe5,
    0x23, 0x60, 0x21, 0xe5, 0x1c, 0x24, 0xfc, 0xfe, 0x8e, 0x1c, 0x8e, 0x01,
    0x87, 0x02, 0x09, 0x87, 0x03, 0x09, 0x87, 0x05, 0x09, 0x87, 0x06, 0x19,
    0x19, 0x19, 0x8a, 0x0f, 0x8b, 0x10, 0x8d, 0x11, 0x8e, 0x12, 0x80, 0x30,
    0xe5, 0x1c, 0x24, 0xfe, 0xfe, 0x8e, 0x1c, 0x8e, 0x01, 0x87, 0x03, 0x09,
    0x87, 0x06, 0x19, 0xee, 0xfa, 0x33, 0x95, 0xe0, 0xfd, 0xfe, 0x8b, 0x0f,
    0x8a, 0x10, 0x8d, 0x11, 0x8e, 0x12, 0xe5, 0x21, 0x70, 0x0e, 0xaa, 0x0f,
    0xab, 0x10, 0xfd, 0xfe, 0x8a, 0x0f, 0x8b, 0x10, 0x8d, 0x11, 0x8e, 0x12,
    0xe5, 0x21, 0x60, 0x23, 0xe5, 0x12, 0x30, 0xe7, 0x1b, 0xc3, 0xe4, 0x95,
    0x0f, 0xfb, 0xe4, 0x95, 0x10, 0xfc, 0xe4, 0x95, 0x11, 0xfd, 0xe4, 0x95,
    0x12, 0xfe, 0x8b, 0x0f, 0x8c, 0x10, 0x8d, 0x11, 0x8e, 0x12, 0x80, 0x03,
    0x75, 0x21, 0x00, 0x75, 0x25, 0x01, 0x79, 0x40, 0x7d, 0x00, 0x7e, 0x00,
    0x75, 0x13, 0x00, 0x85, 0x26, 0x82, 0xc0, 0x06, 0xc0, 0x05, 0xc0, 0x01,
    0x12, 0x02, 0x26, 0xd0, 0x01, 0xd0, 0x05, 0xd0, 0x06, 0xe5, 0x25, 0x70,
    0x14, 0xe5, 0x13, 0xc4, 0x54, 0xf0, 0xfc, 0xe5, 0x13, 0xc4, 0x54, 0x0f,
    0x42, 0x04, 0xe7, 0xfb, 0x4c, 0xf7, 0x19, 0x80, 0x02, 0xa7, 0x13, 0x0d,
    0xbd, 0x00, 0x01, 0x0e, 0xe5, 0x25, 0xb4, 0x01, 0x00, 0xe4, 0x33, 0xf5,
    0x25, 0xe5, 0x0f, 0x45, 0x10, 0x45, 0x11, 0x45, 0x12, 0x70, 0xb9, 0x89,
    0x2c, 0x8d, 0x29, 0x8e, 0x2a, 0xe5, 0x33, 0x45, 0x34, 0x70, 0x05, 0x75,
    0x33, 0x01, 0xf5, 0x34, 0xe5, 0x1e, 0x70, 0x2d, 0xe5, 0x1d, 0x70, 0x29,
    0xaa, 0x33, 0xab, 0x34, 0xac, 0x29, 0x0c, 0x7e, 0x00, 0xc3, 0xec, 0x9a,
    0xee, 0x9b, 0x50, 0x15, 0x75, 0x82, 0x20, 0xc0, 0x03, 0xc0, 0x02, 0x12,
    0x01, 0xd2, 0xd0, 0x02, 0xd0, 0x03, 0x1a, 0xba, 0xff, 0x01, 0x1b, 0x80,
    0xdf, 0x8a, 0x33, 0x8b, 0x34, 0xe5, 0x21, 0x60, 0x11, 0x75, 0x82, 0x2d,
    0x12, 0x01, 0xd2, 0x15, 0x33, 0x74, 0xff, 0xb5, 0x33, 0x02, 0x15, 0x34,
    0x80, 0x2e, 0xe5, 0x29, 0x45, 0x2a, 0x60, 0x28, 0xe5, 0x1f, 0x60, 0x11,
    0x75, 0x82, 0x2b, 0x12, 0x01, 0xd2, 0x15, 0x33, 0x74, 0xff, 0xb5, 0x33,
    0x02, 0x15, 0x34, 0x80, 0x13, 0xe5, 0x20, 0x60, 0x0f, 0x75, 0x82, 0x20,
    0x12, 0x01, 0xd2, 0x15, 0x33, 0x74, 0xff, 0xb5, 0x33, 0x02, 0x15, 0x34,
    0xe5, 0x1d, 0x70, 0x33, 0xad, 0x33, 0xae, 0x34, 0x8d, 0x03, 0x8e, 0x04,
    0x1d, 0xbd, 0xff, 0x01, 0x1e, 0xc3, 0xe5, 0x29, 0x9b, 0xe5, 0x2a, 0x9c,
    0x50, 0x3e, 0xe5, 0x1e, 0x60, 0x06, 0x7b, 0x30, 0x7c, 0x00, 0x80, 0x04,
    0x7b, 0x20, 0x7c, 0x00, 0x8b, 0x82, 0xc0, 0x06, 0xc0, 0x05, 0x12, 0x01,
    0xd2, 0xd0, 0x05, 0xd0, 0x06, 0x80, 0xd1, 0xc3, 0xe5, 0x29, 0x95, 0x33,
    0xe5, 0x2a, 0x95, 0x34, 0x50, 0x0f, 0xe5, 0x33, 0xc3, 0x95, 0x29, 0xf5,
    0x33, 0xe5, 0x34, 0x95, 0x2a, 0xf5, 0x34, 0x80, 0x0b, 0xe4, 0xf5, 0x33,
    0xf5, 0x34, 0x80, 0x04, 0x8d, 0x33, 0x8e, 0x34, 0xa9, 0x2c, 0xad, 0x29,
    0xae, 0x2a, 0x8d, 0x02, 0x8e, 0x04, 0x1d, 0xbd, 0xff, 0x01, 0x1e, 0xea,
    0x4c, 0x60, 0x30, 0xe5, 0x25, 0xb4, 0x01, 0x00, 0xe4, 0x33, 0xf5, 0x25,
    0x70, 0x0a, 0x09, 0xe7, 0xc4, 0x54, 0x0f, 0xfc, 0x8c, 0x13, 0x80, 0x07,
    0x87, 0x04, 0x74, 0x0f, 0x5c, 0xf5, 0x13, 0x85, 0x13, 0x82, 0xc0, 0x06,
    0xc0, 0x05, 0xc0, 0x01, 0x12, 0x01, 0xf5, 0xd0, 0x01, 0xd0, 0x05, 0xd0,
    0x06, 0x80, 0xc3, 0xe5, 0x1d, 0x70, 0x03, 0x02, 0x02, 0x7f, 0xad, 0x33,
    0xae, 0x34, 0x8d, 0x03, 0x8e, 0x04, 0x1d, 0xbd, 0xff, 0x01, 0x1e, 0xeb,
    0x4c, 0x70, 0x03, 0x02, 0x02, 0x7f, 0x75, 0x82, 0x20, 0xc0, 0x06, 0xc0,
    0x05, 0x12, 0x01, 0xd2, 0xd0, 0x05, 0xd0, 0x06, 0x80, 0xe0, 0x8f, 0x82,
    0x12, 0x01, 0xd2, 0x02, 0x02, 0x7f, 0x85, 0x14, 0x82, 0x85, 0x15, 0x83,
    0x22, 0xaa, 0x82, 0xab, 0x83, 0x12, 0x08, 0xee, 0x60, 0x03, 0xa3, 0x80,
    0xf8, 0xc3, 0xe5, 0x82, 0x9a, 0xf5, 0x82, 0xe5, 0x83, 0x9b, 0xf5, 0x83,
    0x22, 0xe5, 0x82, 0x85, 0x38, 0xf0, 0xa4, 0xc5, 0x82, 0xc0, 0xf0, 0x85,
    0x39, 0xf0, 0xa4, 0xd0, 0xf0, 0x25, 0xf0, 0xc5, 0x83, 0x85, 0x38, 0xf0,
    0xa4, 0x25, 0x83, 0xf5, 0x83, 0x22, 0x20, 0xf7, 0x14, 0x30, 0xf6, 0x14,
    0x88, 0x83, 0xa8, 0x82, 0x20, 0xf5, 0x07, 0xe6, 0xa8, 0x83, 0x75, 0x83,
    0x00, 0x22, 0xe2, 0x80, 0xf7, 0xe4, 0x93, 0x22, 0xe0, 0x22, 0x75, 0x82,
    0x00, 0x22, 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, 0x72, 0x6c,
    0x64, 0x21, 0x0a, 0x00, 0x39, 0x78, 0x39, 0x20, 0x6d, 0x75, 0x6c, 0x74,
    0x69, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x74,
    0x61, 0x62, 0x6c, 0x65, 0x3a, 0x0a, 0x00, 0x25, 0x64, 0x2a, 0x25, 0x64,
    0x3d, 0x25, 0x30, 0x32, 0x64, 0x20, 0x00, 0x0a, 0x00, 0x3c, 0x4e, 0x4f,
    0x20, 0x46, 0x4c, 0x4f, 0x41, 0x54, 0x3e, 0x00
};
#define  hs_mcs_51_rom_helloworld_stdio_len   2384

const hs_mcs_51_rom_t hs_mcs_51_rom_helloworld_stdio=
{
    hs_mcs_51_rom_helloworld_stdio_bin,
    hs_mcs_51_rom_helloworld_stdio_len,
    HS_MCS_51_ROM_PSBANK_C8051F120_SFR_ADDRESS
};
